
*Appendix Table 4: Individual fixed effects logistic regression model on labor supply and work time
version 15.1
cd "${mypath}\CHNS_project\01_data\02_posted\"

log using "${mypath}\CHNS_project\03_log_files\09_appendix_table_4.log", replace

use CHNS_1993_2015_20_imputed.dta,clear
mi import ice, automatic

*generate exclusion condition, that is, people who work in agriculture in urban area
gen be_farmer = (migrant_group != 2 & occupation == 3 & work_unit == 4) if be_employed == 1

*generate "over the statutory hours last week"
gen over_lastw = hours_lastw1 > 44 if employed_last1 == 1

*assign outcome variables to the local macro
local outcome_1 "be_employed"
local outcome_2 "over_lastw"

*assign key independent variables to the local macro
local inde "year1997 year2000 year2004 year2006 year2009 year2011 year2015 be_migrant be_migrant##year1997 be_migrant##year2000 be_migrant##year2004 be_migrant##year2006 be_migrant##year2009 be_migrant##year2011 be_migrant##year2015"

*assign control variables to the local macro
local control "age26_30 age31_35 age36_40 age41_45 age46_50 age51_55 year_education marital_status h_group1 h_group2 h_group4 h_group5 num_child num_elderly population pcgdp child_elder percent_farmer service_sector"

*predict inverse mills ratio
prob employed_last1 year1997 year2000 year2004 year2006 year2009 year2011 year2015 be_migrant be_migrant##year1997 be_migrant##year2000 be_migrant##year2004 be_migrant##year2006 be_migrant##year2009 be_migrant##year2011 be_migrant##year2015 age26_30 age31_35 age36_40 age41_45 age46_50 age51_55 gender ethnicity year_education marital_status h_group1 h_group2 h_group4 h_group5 num_child num_elderly population pcgdp child_elder percent_farmer service_sector Liaoning Heilongjiang Shandong Henan Hubei Hunan Guangxi Guizhou if be_rural_resident == 0 & time != 1 & be_farmer != 1
predict gw_urban, xb
gen lambda_urban = normalden(gw_urban)/normal(gw_urban) if employed_last1 == 1 & be_rural_resident == 0 & time != 1 & be_farmer !=  1
           
local path "${mypath}\CHNS_project\04_tables\appendix_table_4\"

*logit model for outcome1
eststo: mi estimate,post esampvaryok: clogit `outcome_1' `inde' `control' if be_rural_resident == 0 & time != 1 & be_farmer !=  1 & degree_education <= 3,group(IDind) vce(cl IDind) 
est store outcome1,title(outcome1)

*logit model for outcome2
eststo: mi estimate,post esampvaryok: clogit `outcome_2' `inde' `control' lambda_urban if employed_last1 == 1 & be_rural_resident == 0 & time != 1 & be_farmer !=  1 & degree_education <= 3,group(IDind) vce(cl IDind) 
est store outcome2,title(outcome2)

esttab outcome1 outcome2 using "`path'appendix_table_4.csv", eform constant b(3) star(+ 0.10 * 0.05 ** 0.01) se(%9.3f) pr2 replace nogap label nonumbers stats(N_mi)

log close
